package cn.lingyangwl.agile.food.core.controller.admin;

import cn.lingyangwl.agile.food.model.rqrs.sku.*;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.agile.food.core.service.StockDocumentDetailService;
import cn.lingyangwl.framework.core.response.Resp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 库存单据明细
 * 
 * @author shenguangyang
 */
@Api(tags = "库存单据明细")
@RestController
@RequestMapping("/skuStockInOut/detail")
public class SkuStockInOutDetailController {
    @Resource
    private StockDocumentDetailService stockDocumentDetailService;

    @ApiOperation(value = "分页库存单据明细")
    @GetMapping("/page")
    @RamResource(action = "shopGoods:skuStockInOutDetail:query", name = "查询库存单据详情", type = ActionType.READ)
    public Resp<IPage<SkuInOutDetailResp>> pageDetail(@Validated SkuInOutDetailPageReq req) {
        return Resp.ok(stockDocumentDetailService.pageDetail(req));
    }

    @ApiOperation(value = "通过id查找库存单据明细")
    @GetMapping("/get")
    @RamResource(action = "shopGoods:skuStockInOutDetail:query", name = "查询库存单据详情", type = ActionType.READ)
    public Resp<SkuInOutDetailResp> getDetail(@RequestParam(value = "id") Long id) {
        return Resp.ok(stockDocumentDetailService.getDetail(id));
    }
  
    @ApiOperation(value = "保存库存单据明细")
    @PostMapping("/save")
    @RamResource(action = "shopGoods:skuStockInOutDetail:save", name = "保存库存单据详情", type = ActionType.WRITE)
    public Resp<?> saveDetail(@Validated @RequestBody SkuInOutDetailSaveReq req) {
        return Resp.ok(stockDocumentDetailService.saveDetail(req));
    }
  
    @ApiOperation(value = "更新库存单据明细")
    @PostMapping("/update")
    @RamResource(action = "shopGoods:skuStockInOutDetail:update", name = "更新库存单据详情", type = ActionType.WRITE)
    public Resp<?> updateDetail(@Validated @RequestBody SkuInOutDetailUpdateReq req) {
        return Resp.ok(stockDocumentDetailService.updateDetail(req));
    }
  
    @ApiOperation(value = "批量删除库存单据明细")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "shopGoods:skuStockInOutDetail:delete", name = "删除库存单据详情", type = ActionType.WRITE)
    public Resp<?> batchDeleteDetail(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(stockDocumentDetailService.batchDeleteDetail(ids));
    }
  
    @ApiOperation(value = "删除库存单据明细")
    @DeleteMapping("/delete")
    @RamResource(action = "shopGoods:skuStockInOutDetail:delete", name = "删除库存单据详情", type = ActionType.WRITE)
    public Resp<?> deleteDetail(@RequestParam(value = "id") Long id) {
        return Resp.ok(stockDocumentDetailService.deleteDetail(id));
    }
}
